post netnewswire item to delicious bookmarks applescript

for blog reading i use the amazing (and free!) software from newsgator called NetNewsWire.

i discovered an applescript for posting post currently being read to my delicious bookmarks.

this was pretty good as it was, but, but i wanted a bit more, so i modified it to prompt for additional tags.

i have also added support for growl notifications, if growl is running.

when you run the script for the first time, it prompts you enter your username, password, and default tags.

you only need to enter that stuff once: after that it just runs.

additionally, i set up a quickilver trigger to run when i push “control + d”, scoped only to NNW.

so, now every time i wish to save whatever it is i am reading in NNW, i just hit “control + d” and it prompts for tags, then runs in the background.

its fast and works great.

to use it yourself, copy the script below and open the Script Editor (included in mac os x).

paste it in, and save it to:

~/Library/Scripts/Applications/NetNewsWire/to read in delicious.scpt

 
property usernamePasswordString : ""
property tagsString : ""
 
on run
	checkUsernameAndPassword()
	postToDelicious()
end run
 
on postToDelicious()
	tell application "NetNewsWire"
		if exists selectedHeadline then
 
			set theResults to display dialog "Enter tags for this item" default answer ""
			if button returned of theResults is "OK" then
				set myTags to text returned of theResults
			end if
 
			set thisHeadline to (title of selectedHeadline)
 
			set u to "\"?&url=" & (URL of selectedHeadline) & ¬
				"&description=" & (title of selectedHeadline) & ¬
				"&tags=" & tagsString & " " & myTags & "\""
			set curlStatement to "/usr/bin/curl -u " & usernamePasswordString & " -d " & u & " https://api.del.icio.us/v1/posts/add"
			set retValue to do shell script curlStatement
			if retValue contains "wrong" then
				display dialog "Headline did not post to Delicious. Something went wrong."
			else
 
 
 
				set the enabledNotificationsList to ¬
					{"Item Posted to Delicious"}
 
				tell application "System Events"
					set growlRunning to ¬
						(count of (every process whose name is "GrowlHelperApp")) > 0
				end tell
 
				if growlRunning then
					tell application "GrowlHelperApp"
 
						register as application ¬
							"scriptNetNewsWire" all notifications enabledNotificationsList ¬
							default notifications enabledNotificationsList ¬
							icon of application "NetNewsWire"
 
						notify with name ¬
							"Item Posted to Delicious" title thisHeadline description "Posted to Delicious with tags: \"" & myTags & ¬
							"\"" application name "scriptNetNewsWire" icon of application "NetNewsWire"
					end tell
				end if
 
			end if
		else
			display dialog "Please select a headline to post to del.icio.us"
		end if
	end tell
end postToDelicious
 
on checkUsernameAndPassword()
	-- Check to see if the file where our username and password are stored exists
	try
		do shell script "cd " & POSIX path of (path to preferences as text) & "; ls | grep com.flickerbulb.toread.txt"
		try
			set prefFile to ((path to preferences as text) & "com.flickerbulb.toread.txt")
			open for access file prefFile with write permission
			set prefs to read file prefFile using delimiter {return}
			close access file prefFile
			set usernamePasswordString to item 1 of prefs
			set tagsString to item 2 of prefs
		on error e
			close access file prefFile
		end try
	on error
		set username to text returned of (display dialog "Please enter your Delicious username" default answer "username")
		set pass to text returned of (display dialog "Please enter your Delicious password" default answer "password")
		set tags to text returned of (display dialog "Please enter any desired default tags" default answer "toread ")
		try
			set prefFile to ((path to preferences as text) & "com.flickerbulb.toread.txt")
			open for access file prefFile with write permission
			set eof of file prefFile to 0
			write username & ":" & pass & {return} & tags to file prefFile
			close access file prefFile
		on error e
			close access file prefFile
		end try
		set usernamePasswordString to username & ":" & pass
		set tagsString to tags & " "
	end try
end checkUsernameAndPassword

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.